package com.one.blocks.mvc.exception;

import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author linfuxin Created on 2022-02-14 11:22:15
 */
@Configuration
@ConditionalOnProperty(prefix = "app.blocks.mvc.exception.handler", name = "enable", havingValue = "true", matchIfMissing = true)
@AutoConfigureBefore({ErrorMvcAutoConfiguration.class})
public class ExceptionHandlerConfig {

    /**
     * TODO 404走BasicErrorController#error方法，直接返回json，暂时未找到统一异常数据结构方法
     *
     * @return JsonViewResolver
     */
    @Bean
    @ConditionalOnMissingBean(JsonViewResolver.class)
    public JsonViewResolver jsonViewResolver() {
        return new JsonViewResolver();
    }
}
